#!user/bin/env python3
# -- coding: utf-8 --
# @Createtime：2023/8/20
# @Updatetime：20:43
# @Author：Test008
# @File：1-ui元素定位.py
# @Description：By.CSS_SELECTOR
from selenium import webdriver
from selenium.webdriver.common.by import By
import time

driver = webdriver.Chrome()
driver.implicitly_wait(3)
driver.get('file:///C:/Users/EDY/PycharmProjects/Appium_test/selenium/testHTML.html')
# 1》id 选择器，具有id的属性
# ele = driver.find_element(By.CSS_SELECTOR, '#abc')
# print(ele.text)

# 2》class 选择器，class
# ele = driver.find_element(By.CSS_SELECTOR, '.abc1')
# print(ele.text)

# 标签选择器，根据标签名称找元素,# 如果存在多个，只会返回找到的第一个
# ele = driver.find_element(By.TAG_NAME, 'a')
# print(ele.text)


# 3》scc的标签选择器，根据标签名称的下标找元素
# ele = driver.find_elements(By.CSS_SELECTOR, 'p')[5]
# print(ele.text)

# 4》分组选择器，符号：,号隔开。可以填多个属性值
# eles = driver.find_elements(By.CSS_SELECTOR, '.abc2,.abc3,#abd')
# for i in eles:
#     print(i.text)

# 5》属性选择器，填标签后面的属性
# ele = driver.find_element(By.CSS_SELECTOR, "[title='qwe']")
# print(ele.text)

# 6》子元素选择器，符号“>”,一层一层往下找 张三，，李四，王五的名字
# ele_list = driver.find_elements(By.CSS_SELECTOR, '.qq > ul > li>a')
# for ele in ele_list:
#     print(ele.text)

# 7》后代选择器，符号：空格隔开。 找到张三的名字
# ele = driver.find_element(By.CSS_SELECTOR, '.qq a')    # '.qq a' 找到的是一个列表，找到张三时直接返回了
# print(ele.text)

# 8》css的下标
# 方法1：find_element(By.CSS_SELECTOR,'.qq li:nth-child(1) a')，数字表示第几个，从1开始；
# 方法2：find_elements(By.CSS_SELECTOR,'.qq a')[0],数字表示第几个，从0开始

# 9》获得第一个名字
# 法1:
# ele=driver.find_element(By.CSS_SELECTOR,'.qq li:nth-child(1) a')
# 法2:
# ele = driver.find_element(By.CSS_SELECTOR, '.qq li:first-child a')
# 法3:
# ele=driver.find_elements(By.CSS_SELECTOR,'.qq a')[0]
# print(ele.text)

# 获得第三个名字 :nth-child(3)
# ele=driver.find_element(By.CSS_SELECTOR,'.qq li:nth-child(3) a')
# print(ele.text)

# 获得最后一个名字 :last-child
# ele = driver.find_element(By.CSS_SELECTOR, '.qq li:last-child a')
# print(ele.text)

# 获得倒数第二个 :nth-last-child(2)
ele=driver.find_element(By.CSS_SELECTOR,'.qq li:nth-last-child(2) a')
print(ele.text)


time.sleep(3)
driver.quit()
